package com.project.demo.service.impi;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.demo.entity.Land;
import com.project.demo.mapper.Landmapper;
import com.project.demo.service.LandService;
import com.project.demo.vo.AllLandVo;
import com.project.demo.vo.LandVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
    @Service
public class LandServiceimpi implements LandService {
    @Autowired
    private Landmapper landmapper;

    @Override
    public LandVo<AllLandVo> FindLandVo(Integer page,Integer limit) {
        LandVo landVo = new LandVo();
        landVo.setCode(0);
        landVo.setMsg("");
        IPage<Land>landIPage = new Page<>(page,limit);
        IPage<Land>result =  landmapper.selectPage(landIPage,null);
        landVo.setCount(result.getTotal());
        List<Land> landList = result.getRecords();
        List<AllLandVo> allLandVoList = new ArrayList<>();
        for (Land land1 : landList){
            AllLandVo allLandVo = new AllLandVo();
            BeanUtils.copyProperties(land1,allLandVo);
            allLandVoList.add(allLandVo);
        }
        landVo.setData(allLandVoList);
        return landVo;
    }

    @Override
    public LandVo<AllLandVo> FindAllLandVo() {
        LandVo landVo = new LandVo();
        landVo.setCode(0);
        landVo.setMsg("");
        landVo.setCount(Long.valueOf(landmapper.selectCount(null)));
        List<Land>landList = landmapper.selectList(null);
        List<AllLandVo> allLandVoList = new ArrayList<>();
        for (Land land1 : landList){
            AllLandVo allLandVo = new AllLandVo();
            BeanUtils.copyProperties(land1,allLandVo);
            allLandVoList.add(allLandVo);
        }
        landVo.setData(allLandVoList);
        return landVo;
    }

    @Override
    public Integer deleteVo(Integer name) {
        return landmapper.deleteVo(name);
    }
        @Override
        public Integer insertVo(Integer name,String arable,Integer urban,
                                Integer transportation,Integer tps,Integer woodland,
                                Integer waters,Integer naturalland,Integer industrialland, Integer time)
        {return landmapper.insertVo(name,arable,urban,transportation,
                tps,woodland,waters,naturalland,industrialland,time);}
}
